package com.hmall.common.interceptor;

import com.hmall.common.utils.UserHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

@Slf4j
//@Component  // 通过自动装配原理，将拦截器自动注入其他引入feign-api的微服务
public class MyFeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {

        // ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        template.header("authorization", "2"); // 给每个feign请求添加header
        UserHolder.setUser(2L);
    }
}
